#!/usr/bin/perl -w

use strict;
use warnings;

# log_file_name = $log[case_name]
my %log;
# parse input file
while (<>)
{
    chomp(my $case_name = $_);
    s/\.txt$/\.log/;
    chomp ($log{$case_name} = $_);
}

&print_Makefile(\%log);

sub print_Makefile() {
    local $_;
    my $href_log = shift;
    my @case_list;
    foreach (sort keys %$href_log) {
	s/\.txt$//;
	push @case_list, $_;
    }
    # print the head
    print "RUN_SH := ./run.sh\n\n"; # script to run a single case
    my $list = join " ", @case_list;
    print ".PHONY: all $list\n";
    print "all: $list\n\n";
    # print the body
    foreach (@case_list) {
	print "$_:\n";
	if (/\.\/no/) { # ignore known issues
	    print "\t-\$(RUN_SH) \$@\n\n";
	} else {
	    print "\t\$(RUN_SH) \$@\n\n";
	}
	#print "\t\./run.sh \$@\n\n";
    }
    # print the tail
    print ".PHONY: clean\n";
    print "clean:\n";
    print "\t\$(RM) ";
    print join(" ", (values %$href_log));
    print "\n";
}
